package org.stvd.service.admin.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.stvd.core.util.DateUtil;
import org.stvd.core.util.StringUtil;
import org.stvd.entities.admin.UserBase;
import org.stvd.entities.admin.Users;
import org.stvd.repository.admin.UserBaseDao;
import org.stvd.repository.admin.UserLoginDao;
import org.stvd.repository.admin.UsersDao;
import org.stvd.service.admin.UserBaseService;
import org.stvd.service.base.impl.BaseServiceImpl;

@Service("userBaseService")
@Transactional
public class UserBaseServiceImpl extends BaseServiceImpl<UserBase> 
    implements UserBaseService {
    
    @Resource(name = "UserBaseDao")
    private UserBaseDao userBaseDao;
    @Resource(name = "UsersDao")
    private UsersDao usersDao;
    @Resource(name = "UserLoginDao")
    private UserLoginDao userLoginDao;
    
    @Override
    public void updateUserBase(UserBase userBase) {
        Users user = usersDao.findByPk(Users.class, userBase.getUserId());
        if (user != null) {
            user.setUname(userBase.getNickName());
            user.setModifyDate(DateUtil.getSystemDate());
            usersDao.update(user);
            userBaseDao.update(userBase);
        }
    }
    
    @Override
    public List<UserBase> listUserBase(String loginCode, String nickName, String depIds, String roleIds, String guid) {
        return userBaseDao.listUserBase(loginCode, nickName, depIds, roleIds, guid);
    }
    
    @Override
    public List<UserBase> listUserBaseByCompId(String compId) {
        return userBaseDao.listUserBaseByCompId(compId);
    }
    
    @Override
    public List<UserBase> listUserBaseByTeamId(String teamId) {
        return userBaseDao.listUserBaseByTeamId(teamId);
    }
    
    @Override
    public List<UserBase> listUserBaseByDepCode(String depCode, String guid) {
        if(StringUtil.isEmpty(depCode) || StringUtil.isEmpty(guid)) {
            return null;
        }
        return userBaseDao.listUserBaseByDepCode(depCode, guid);
    }
    
    @Override
    public List<UserBase> listUserBaseByRoleCode(String roleCode, String guid) {
        if(StringUtil.isEmpty(roleCode) || StringUtil.isEmpty(guid)) {
            return null;
        }
        return userBaseDao.listUserBaseByRoleCode(roleCode, guid);
    }
}